import { CHANGE_INPUT_VALUE, CHANGE_LIST, DELETE_TODOITEM } from "./actionTypes";

const defaultState = {
    inputValue: "123",
    list: [1, 2]
}

export default ((state = defaultState, action) => {
    if (action.type === CHANGE_INPUT_VALUE) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        console.log(newState)
        return newState;
    } else if (action.type === CHANGE_LIST) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.list.push(action.value);
        newState.inputValue = "";
        return newState;
    } else if (action.type === DELETE_TODOITEM) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.index, 1);
        return newState;
    }
    return state
})